/**
 * 带滴管瓶子（BaCl2，NaOH,NaCO3）
 */
DropBottle = cc.Node.extend({
	labelTag:0,
	ctor:function(parent,tag){
		this._super();
		parent.addChild(this,10,tag);
		this.init(tag);
	//	this.initLabel(tag);
	},
	init:function(tag){
		var name = "";
		if (TAG_HHCL_NODE == tag){
			var bottle = new Button(this, 10, TAG_HHCL, "#bottle1.png",this.callback);
		//	bottle.setCascadeOpacityEnabled(true);
			var  lid  = new Button(this, 9, TAG_HCORK, "#lid5.png",this.callback);
			//lid.setPosition(0,45);
			name = "浓硫酸";
		}else if(TAG_HBOTTLE_NODE == tag){
			var bottle = new Button(this, 10, TAG_HBOTTLE, "#bottle1.png",this.callback);
			
			var  lid  = new Button(this, 9, TAG_HCORK1, "#lid5.png",this.callback);
			var h2so4 = new cc.Sprite("#h2so4.png");
			bottle.addChild(h2so4);
			h2so4.setPosition(22,30);
		}
		else if(TAG_LIB_BURETTE == tag){
			var bottle = new Button(this, 9, TAG_WATER1, "#bottle1.png",this.callback);
			var  lid  = new Button(this, 8, TAG_BURETTE, "#drop_bottle2.png",this.callback);
			name = "蒸馏水";
		} else if(TAG_FENTAI_NODE == tag){
			var bottle = new Button(this, 9, TAG_FENTAI, "#bottle1.png",this.callback);
			var  lid  = new Button(this, 8, TAG_FENTAIDIGUAN, "#lid5.png.png",this.callback);
			name = "酚酞";
		} else if(TAG_NBOTTLE_NODE == tag){
			var bottle = new Button(this, 10, TAG_NBOTTLE, "#bottle1.png",this.callback);
			var  lid  = new Button(this, 9, TAG_NCORK, "#lid5.png.png",this.callback);
			name = "NaOH";
		} 
		this.setCascadeOpacityEnabled(true);
		bottle.setCascadeOpacityEnabled(true);
		if(TAG_HBOTTLE_NODE==tag){
			lid.setPosition(0,45);
			lid.setScale(1.0);
		}else{
			lid.setPosition(0,45);
		}
		
		var label = new cc.LabelTTF(name,gg.fontName,12);
		label.setColor(cc.color(0,0,0));
		label.setPosition(bottle.width*0.5,bottle.height*0.35);
		bottle.addChild(label, 11,TAG_LABEL);
		
	},
	xuanzhuan:function(){
		var frames=[];
		for(var i=1;i<6;i++){
			var str ="liusuan/"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			frames.push(frame);
		}

		var animation = new cc.Animation(frames,0.1);//负责动画序列
		var action = new cc.Animate(animation);//帧动画的动作创建
		return action;
	},
	initLabel:function(tag){
		this.labelTag = tag;
		var name = "";
		if(TAG_HHCL_NODE == tag){
			name = "浓Hcl";
		} else if(TAG_HCL_NODE == tag){
			name = "测Hcl";
		} else if(TAG_FENTAI_NODE == tag){
			name = "酚酞";
		} else if(TAG_NAOH_NODE == tag){
			name = "NaOH.png";
		} else if(TAG_ALCOHOL == tag){
			name = "酒精";
		}else if(TAG_HBOTTLE_NODE==tag){
		
			name = "NaOH.png";
		}
		var label = new cc.LabelTTF(name,gg.fontName,12);
		label.setColor(cc.color(0,0,0));
		label.setPosition(0, -10);
		this.addChild(label, 11);
	},
	genPoint:function(p,count){
		count --;
		if(count <= 0){
			return;
		}
		var wp = new cc.Sprite("#wpoint.png")
		wp.setPosition(10, 0);
		p.addChild(wp);
		var move = cc.moveBy(0.5, cc.p(0, -45));
		var func = cc.callFunc(function(){
			wp.removeFromParent(true);
			this.genPoint(p,count);
		}, this);
		var seq = cc.sequence(move, func);
		wp.runAction(seq);
	},
	bezier:function(orig,target,time){
		var my = orig.y > target.y ? orig.y - target.y : target.y - orig.y;
		var pos1 = cc.p(orig.x, target.y + my / 2);
		var pos2 = cc.p(target.x, target.y + my / 2);
		var pos3 = target;
		return cc.bezierTo(time, [pos1, pos2, pos3]);
	},
	callback:function(p){
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);	
	
		var hand = new Hand();
	
		
		switch(p.getTag()){
		case TAG_HCORK:
			var move = cc.moveTo(1,cc.p(-50,-30));
			var rotate = cc.rotateTo(0.5, 180);
			var spawn =cc.spawn(move,rotate);
			var fade3= cc.fadeTo(0.5,0);
			var delay = cc.delayTime(0.5);
			var seq = cc.sequence(cc.callFunc(function(){
				p.runAction(cc.fadeTo(1.5, 0));
			}, this),spawn,cc.callFunc(this.getParent().flowNext, this),delay,fade3);
			p.runAction(seq);							
			break;
		case TAG_HHCL:
			var cylindernode = this.getParent().getChildByTag(TAG_CYLINDER_NODE);
			var  cylinder=cylindernode.getChildByTag(TAG_CYLINDER);
			p.setCascadeOpacityEnabled(true);
			//var ber = cc.bezierTo(1.5, [cc.p(590,320),cc.p(550,320),cc.p(518,235)]);
			var ber = cc.moveBy(1.5,cc.p(-115,-105));
			var rotate = cc.rotateTo(2, -90);
			var spawn = cc.spawn(ber,rotate);
			var delay = cc.delayTime(2.5);
			var moveBack = cc.moveBy(1,cc.p(15,180));
			var rotate = cc.rotateTo(1, 0);
			var spaw2 = cc.spawn(moveBack,rotate);
			
			var seq = cc.sequence(cc.callFunc(function(){
				hand.addrighthand(this, "#hand/hand_right", cc.p(25,-25),0.6);
			}, this),cc.callFunc(function(){
				p.getChildByTag(TAG_LABEL).setVisible(false);
				p.runAction(this.xuanzhuan());
			}, this),cc.delayTime(0.5),spawn, delay,spaw2,cc.callFunc(function(){
				this.runAction(cc.fadeTo(0.5, 0));
				show.kill();
				//this.removeFromParent();
			}, this));
		
			this.runAction(seq);
			var show = new ShowTip1("量取27mL",25,cc.p(300,100));
			
			
			p.runAction(func);
			var rotate1 = cc.rotateTo(1,10);
			var rotate2 = cc.rotateTo(1,0);
			var seq1 = cc.sequence(cc.callFunc(function(){
				hand.addlefthand(cylindernode, "#hand/hand_left", cc.p(-20,25),0.6);
			},this),rotate1,cc.delayTime(3),rotate2,cc.callFunc(function(){
				
				//hand.removehand(cylinder,1,1);
			}, this),cc.callFunc(this.flowNext, this));
			cylindernode.runAction(seq1);
			break;
		case TAG_BURETTE:
	
		var burette=this.getChildByTag(TAG_BURETTE);
		var water1=this.getChildByTag(TAG_WATER1);
//		var move =cc.moveBy(1, -179, -65);
		var move=cc.bezierBy(1.5, [cc.p(0,55),cc.p(-100,-25),cc.p(-179,-65)]);
//		var moveback3=cc.moveBy(1,179,65);
		var moveback3=cc.bezierBy(1.5, [cc.p(-5,250),cc.p(200,140),cc.p(179,65)]);
		var delay3=cc.delayTime(4);
		var seq3=cc.sequence(cc.callFunc(function(){
			
		}, this),move,cc.callFunc(function(){
			this.genPoint(p, 6);
			var cly_dtl3 = new cc.Sprite("#cly_dtl3.png");
			cly_dtl3.setAnchorPoint(1, 1);
			cly_dtl3.setOpacity(0);
			cly_dtl3.setRotation(0);
			cly_dtl3.setPosition(0,0);
			p.addChild(cly_dtl3);
			var seq1 = cc.sequence(cc.delayTime(0),cc.fadeTo(0.5,255),cc.delayTime(3.0),cc.fadeTo(0.2,0),cc.callFunc(function(){
				cly_dtl3.removeFromParent();
			},this));
			cly_dtl3.runAction(seq1);

			var clyLine = new cc.Sprite("#cly_line1.png");
			var spawn3=cc.spawn(cc.scaleTo(0.1,0.4),cc.fadeTo(0.5, 150));
			clyLine.setOpacity(0);
			cly_dtl3.addChild(clyLine);
			clyLine.setPosition(cly_dtl3.width * 0.5+4, 20);
			clyLine.runAction(cc.sequence(cc.delayTime(0),spawn3,cc.moveBy(1.5,cc.p(0,cly_dtl3.height * 0.4-5)),cc.delayTime(1),cc.fadeTo(0.5, 0)));
			
			var eye = new cc.Sprite("#eye.png");
			var spawn3=cc.fadeTo(0.5, 150);
			eye.setOpacity(0);
			cly_dtl3.addChild(eye);
			eye.setPosition(cly_dtl3.width * 0.5+50, 44);
			eye.runAction(cc.sequence(cc.delayTime(0),spawn3,cc.delayTime(3),cc.fadeTo(0.5, 0)));	
		}, this),delay3,moveback3,cc.delayTime(0.3),cc.callFunc(function(){
			burette.runAction(cc.fadeOut(0.5));
			water1.runAction(cc.fadeOut(0.5));
			show.kill();
		},this),cc.callFunc(this.flowNext, this));
		var show = new ShowTip1("溶液凹面恰好与刻度线相切",25,cc.p(210,100));
		
		burette.runAction(seq3);
		
		var volumetricnode = this.getParent().getChildByTag(TAG_VOLUMETRIC_NODE);
		var volumetric=volumetricnode.getChildByTag(TAG_VOLUMETRIC);

		beaLine = volumetricnode.getChildByTag(TAG_BEAKER_LINE1);


		var scale=cc.scaleTo(1,0.26);



		beaLine.runAction(cc.sequence(cc.delayTime(2),cc.spawn(scale,cc.moveBy(6,cc.p(-1,volumetric.height * 0.1)))));

		
		
		
		
		
		break;
		case TAG_HCORK1:
			if(action==ACTION_DO3)
			{
			var move = cc.moveTo(1,cc.p(-50,-30));
			var rotate = cc.rotateTo(0.5, 180);
			var spawn =cc.spawn(move,rotate);
			var fade3= cc.fadeTo(1,0);
			var delay = cc.delayTime(0.5);
			var seq = cc.sequence(spawn,cc.callFunc(this.getParent().flowNext, this));
			p.runAction(seq);		
		    }
			if(action==ACTION_DO4)
			{
				var move = cc.moveBy(1,cc.p(50,71));
				var rotate = cc.rotateBy(0.5, -180);
				var spawn =cc.spawn(move,rotate);
				var fade3= cc.fadeTo(1,0);
				var delay = cc.delayTime(0.5);
				var seq = cc.sequence(spawn,cc.callFunc(this.getParent().flowNext, this));
				p.runAction(seq);		
			}
			break;
		case TAG_HBOTTLE:
			if(action==ACTION_DO1){
				var hcork = this.getChildByTag(TAG_HCORK1);
				var move = cc.moveTo(1.5,cc.p(-50,-30));
				var rotate1 = cc.rotateTo(1,180);
				var spawn1 = cc.spawn(move,rotate1);
				var moveback = cc.moveTo(1.5,cc.p(0,45));
				var rotate2 = cc.rotateTo(1,0);
				var delay3 = cc.delayTime(4);
				var spawn2 = cc.spawn(moveback,rotate2);
				var seq1 = cc.sequence(spawn1,delay3,spawn2,cc.callFunc(this.getParent().flowNext, this));

				var move = cc.moveTo(1,cc.p(150,-270));
				var rotate= cc.rotateTo(1,-60);					
				var moveback= cc.moveTo(2,cc.p(0,0));
				var rotate1= cc.rotateTo(1,0);
				var spawn1 = cc.spawn(moveback,rotate1);
				var delay = cc.delayTime(1);
				var delay1 = cc.delayTime(0.5);
				var seq = cc.sequence(move,delay1,rotate,func,delay,spawn1);
				hcork.runAction(seq1);					
				p.runAction(seq);
		
			}
			if(action==ACTION_DO2){
				var hcork = this.getChildByTag(TAG_HCORK1);
				var move = cc.moveTo(1.5,cc.p(-50,-30));
				var rotate1 = cc.rotateTo(1,180);
				var spawn1 = cc.spawn(move,rotate1);
				var moveback = cc.moveTo(1.5,cc.p(0,45));
				var rotate2 = cc.rotateTo(1,0);
				var delay3 = cc.delayTime(4);
				var spawn2 = cc.spawn(moveback,rotate2);
				var seq1 = cc.sequence(spawn1,delay3,cc.callFunc(this.getParent().flowNext, this));

				var move = cc.moveTo(1,cc.p(170,-280));
				var rotate= cc.rotateTo(1,-60);					
				var moveback= cc.moveTo(0.5,cc.p(170,-280));
				var rotate1= cc.rotateTo(1,0);
				var spawn1 = cc.spawn(moveback,rotate1);
				var delay = cc.delayTime(1);
				var delay1 = cc.delayTime(0.5);
				var seq = cc.sequence(move,delay1,rotate,func,delay,spawn1);
				hcork.runAction(seq1);					
				p.runAction(seq);

			}
			
			break;
		case TAG_FENTAIDIGUAN:
			var move = cc.moveTo(0.5,cc.p(0,100));
			var move1 = cc.moveTo(0.5,cc.p(50,100));
			var movedown = cc.moveTo(2,cc.p(130,-230));					

			var delay = cc.delayTime(1);
			//var delay1 = cc.delayTime(1);
			var seq1 = cc.sequence(move,move1,movedown,func,delay,cc.callFunc(function(){
				this.removeFromParent();
			},this),cc.callFunc(this.getParent().flowNext,this));
			p.runAction(seq1);
			break;
		case TAG_NCORK:
			var move = cc.moveTo(1,cc.p(50,-30));
			var rotate = cc.rotateTo(0.5, 180);
			var spawn =cc.spawn(move,rotate);
			var fade3= cc.fadeTo(1,0);
			var delay = cc.delayTime(0.5);
			var seq = cc.sequence(spawn,cc.callFunc(this.getParent().flowNext, this));
			p.runAction(seq);							
			break;
		case TAG_NBOTTLE:
			if (action==ACTION_DO1){
				var move = cc.moveTo(1.5,cc.p(95,-85));
				var rotate= cc.rotateTo(1,-60);
				var delay = cc.delayTime(1);
				var delay1 = cc.delayTime(1.5);
				var moveback= cc.moveTo(1.5,cc.p(0,0));
				var rotate1= cc.rotateTo(1,0);
				var spawn1 = cc.spawn(moveback,rotate1);
				var seq = cc.sequence(move,rotate,func,delay,spawn1,cc.callFunc(this.getParent().flowNext,this));

				var jianshi = this.getParent().getChildByTag(TAG_JIANSHI_NODE);			
				var rotate = cc.rotateTo(1,45);
				var rotate2=cc.rotateTo(1,0);
				var seq1 = cc.sequence(delay1,rotate,delay,rotate2);

				p.runAction(seq);
				jianshi.runAction(seq1);
				break;			
			}
			
			if (action==ACTION_DO2){
				var move = cc.moveTo(1.5,cc.p(95,-85));
				var rotate= cc.rotateTo(1,-60);
				var delay = cc.delayTime(1);
				var delay1 = cc.delayTime(1.5);
				var moveback= cc.moveTo(1.5,cc.p(0,0));
				var rotate1= cc.rotateTo(1,0);
				var spawn1 = cc.spawn(moveback,rotate1);
				var seq = cc.sequence(move,rotate,func,delay,spawn1,cc.callFunc(function(){
					this.removeFromParent();
				},this),cc.callFunc(this.getParent().flowNext,this));

				var jianshi = this.getParent().getChildByTag(TAG_JIANSHI_NODE);			
				var rotate = cc.rotateTo(1,45);
				var rotate2=cc.rotateTo(1,0);
				var seq1 = cc.sequence(delay1,rotate,delay,rotate2);

				p.runAction(seq);
				jianshi.runAction(seq1);
				break;			
			}
			

		}
	},
	actionDone:function(p){
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_HHCL:
			var cylindernode = this.getParent().getChildByTag(TAG_CYLINDER_NODE);
			var cylinder = cylindernode.getChildByTag(TAG_CYLINDER);
			cylinder.setCascadeOpacityEnabled(true);
			var clyDtl = new cc.Sprite("#cly_dtl.png");
			clyDtl.setPosition(cylinder.width + clyDtl.width * 0.5,cylinder.height * 0.5);
			//clyDtl.setOpacity(0);
			clyDtl.setCascadeOpacityEnabled(true);
			cylinder.addChild(clyDtl);
			var fade1 = cc.fadeTo(0.5, 255);
			var delay = cc.delayTime(3);
			var fade2 = cc.fadeTo(0.5,0);
			var sequence = cc.sequence(delay,fade1, delay, fade2,cc.callFunc(function(){
				clyDtl.removeFromParent();
			},this));
			clyDtl.runAction(sequence);
			var clyLine = new cc.Sprite("#cly_line1.png");
			var fade3 = cc.fadeTo(1.5, 255);
			clyLine.setPosition(clyDtl.width * 0.5, 5);
			
			var spawn3=cc.spawn(cc.scaleTo(1.5,1.2,1.2),fade1);
			clyLine.setOpacity(0);
			clyDtl.addChild(clyLine);
			
			
			
			
			clyLine.runAction(cc.sequence(spawn3,cc.moveBy(1.5,cc.p(0,clyDtl.height * 0.5-40)),cc.moveBy(1.5,cc.p(0,clyDtl.height * 0.5+5))));	
			

			
			

//			var clyDtl = new cc.Sprite("#cly_dtl2.png");
//
//			clyDtl.setPosition(loadCyl1.width + clyDtl.width * 0.5,loadCyl1.height * 0.5);
////			clyDtl.setOpacity(0);
//			//clyDtl.setCascadeOpacityEnabled(true);
//			loadCyl1.addChild(clyDtl);
//			var fade1 = cc.fadeTo(2.5, 255);
//			var delay = cc.delayTime(4.5);
//			var delay2 = cc.delayTime(3.5);
//			var fade2 = cc.fadeTo(0.5,0);
//			var fade3 = cc.fadeTo(1,0);
//			var sequence = cc.sequence(delay, fade2,cc.callFunc(function(){
//				clyDtl.removeFromParent();
//			},this));
//			clyDtl.runAction(sequence);
//			var clyLine = new cc.Sprite("#cly_line1.png");
//			var spawn3=cc.Spawn(cc.scaleTo(1.2,1.2),fade1);
//			clyLine.setOpacity(0);
//			clyDtl.addChild(clyLine);
//			clyLine.setPosition(clyDtl.width * 0.5, 5);
//			clyLine.runAction(cc.sequence(spawn3,cc.moveBy(1.5,cc.p(0,clyDtl.height * 0.7+1)),fade3));	
//			
			
			
			
			
			

            break;
			
			
			
			
	
			
		
			
		case TAG_HBOTTLE:
			if(action==ACTION_DO1){
				var sbeaker = this.getParent().getChildByTag(TAG_SBEAKER);
				sbeaker.setCascadeOpacityEnabled(true);
				sbLine = new cc.Sprite("#beaker_line.png");
				sbLine.setScale(0.6);
				sbeaker.addChild(sbLine,1,TAG_SHOW);
				sbLine.setPosition(sbeaker.width * 0.5,  + 5);

				var shuiliu = new cc.Sprite("#shuiliu.png");
				shuiliu.setAnchorPoint(1, 1);
				shuiliu.setScale(0);
				shuiliu.setRotation(60);
				shuiliu.setPosition(10, 85);
				p.addChild(shuiliu);
				var seq = cc.sequence(cc.scaleTo(0.5,0.6),cc.delayTime(0.5),cc.fadeTo(0.2,0),cc.callFunc(function(){
					shuiliu.removeFromParent();
				},this));
				sbLine.runAction(cc.moveBy(1,cc.p(0,sbeaker.height *0.5)));
				shuiliu.runAction(seq);

			}
			if(action==ACTION_DO2){
				var sbeaker = this.getParent().getChildByTag(TAG_SBEAKER);
				sbeaker.setCascadeOpacityEnabled(true);
				sbLine = new cc.Sprite("#beaker_line.png");
				sbLine.setScale(0.6);
				sbeaker.addChild(sbLine,1,TAG_SHOW);
				sbLine.setPosition(sbeaker.width * 0.5,  + 5);

				var shuiliu = new cc.Sprite("#shuiliu.png");
				shuiliu.setAnchorPoint(1, 1);
				shuiliu.setScale(0);
				shuiliu.setRotation(60);
				shuiliu.setPosition(10, 85);
				p.addChild(shuiliu);
				var seq = cc.sequence(cc.scaleTo(0.5,0.5),cc.delayTime(0.5),cc.fadeTo(0.2,0),cc.callFunc(function(){
					shuiliu.removeFromParent();
				},this));
				sbLine.runAction(cc.moveBy(1,cc.p(0,sbeaker.height * 0.2)));
				shuiliu.runAction(seq);

			}
			break;
		case TAG_FENTAIDIGUAN:
//			var shuidi = new cc.Sprite("#shuidi0.png");
//			shuidi.setPosition(p.width/2,-p.height*0.3);
//			p.addChild(shuidi);
//			var fadein = cc.fadeIn(0.5);
			var delay = cc.delayTime(0.5);
//			var fade = cc.fadeTo(0.2,0);
//			var seq = cc.sequence(fadein,delay,fade);
//			shuidi.runAction(seq);
			this.genPoint(p, 4);
			var beakerflask = this.getParent().getChildByTag(TAG_BEAKERFLASK);
			var move = cc.moveTo(1,cc.p(1000,120));
			var seq1 = cc.sequence(cc.delayTime(1.5),move);
			beakerflask.runAction(seq1);
			break;
		case TAG_NBOTTLE:
			if (action==ACTION_DO1){
				var jianshi = this.getParent().getChildByTag(TAG_JIANSHI_NODE);
				jianshi.setCascadeOpacityEnabled(true);
				var clyDtl = new cc.Sprite("#js.png");
				clyDtl.setPosition(jianshi.width + clyDtl.width * 0.5,jianshi.height * 0.5);
				clyDtl.setOpacity(0);
				clyDtl.setCascadeOpacityEnabled(true);
				jianshi.addChild(clyDtl);
				var fade1 = cc.fadeTo(0.5, 255);
				var delay = cc.delayTime(1.5);
				var fade2 = cc.fadeTo(0.5,0);
				var sequence = cc.sequence(fade1, delay, fade2);
				clyDtl.runAction(sequence);
				var clyLine = new cc.Sprite("#cly_line1.png");
				clyDtl.addChild(clyLine);
				clyLine.setPosition(clyDtl.width * 0.5, 0);
				clyLine.runAction(cc.moveBy(1,cc.p(0,clyDtl.height * 0.8-32)));		    	
			}
			if (action==ACTION_DO2){
				var jianshi = this.getParent().getChildByTag(TAG_JIANSHI_NODE);
				jianshi.setCascadeOpacityEnabled(true);
				var clyDtl = new cc.Sprite("#js.png");
				clyDtl.setPosition(jianshi.width + clyDtl.width * 0.5,jianshi.height * 0.5);
				clyDtl.setOpacity(0);
				clyDtl.setCascadeOpacityEnabled(true);
				jianshi.addChild(clyDtl);
				var fade1 = cc.fadeTo(0.5, 255);
				var delay = cc.delayTime(1.5);
				var fade2 = cc.fadeTo(0.5,0);
				var sequence = cc.sequence(fade1, delay, fade2);
				clyDtl.runAction(sequence);
				var clyLine = new cc.Sprite("#cly_line1.png");
				clyDtl.addChild(clyLine);
				clyLine.setPosition(clyDtl.width * 0.5, 0);
				clyLine.runAction(cc.moveBy(1,cc.p(0,clyDtl.height * 0.8-32)));		    					
			}
			break;
		}
		
			
	},
	flowNext:function(){

		gg.flow.next();
		cc.log("下一步"+gg.flow.flow.tag);
	}
});